﻿@using Telerik.Web.Mvc
@using Telerik.Web.Mvc.UI
@using Presentation.Web.Admin
@model  IEnumerable<Domain.Dto.SightPointUserSiginDto>
@{
    var targetId = ViewBag.id == null ? 0 : ViewBag.id;
    var sightName = ViewBag.sightname == null ? "" : ViewBag.sightname;
    ViewBag.subtitle = "景点签到管理" + (sightName == "" ? "" : "--" + sightName);
    ViewBag.title = "景点签到管理" + (sightName == "" ? "" : "--" + sightName);
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<input id = "targetId" name = "targetId" type = "hidden" value = "@(targetId)"/>
@{Html.Telerik().Grid(Model)
    .Name("SightSiginGrid")
    .ToolBar(toolBar => toolBar.Template(
    @<text>
    @{
        if (Html.HasUiPermission(this.ViewContext, "searchsightsigin"))
        {
        <label class="customer-label" for="Customers-input">
            用户名:
        </label>
        <input type="text" id="searchSightSigin" value="用户名" data-autocomplete="/sight/searchsightsigin" />
        <input type='button' value='我要搜索' class='t-button' onclick='searchChange()' />
        }
    }
    <a href='/sight/detail/@(targetId)' class='t-button' style="float: right;">返回</a>
    </text>))
    .Columns(columns =>
    {
        columns.Bound(o => o.Id).Width(50).Title("系统Id").Hidden();

        columns.Bound(o => o.UserName).Width(100).Title("用户名").ReadOnly();
        columns.Bound(o => o.UserId).Width(200).Title("用户Id").Hidden();

        columns.Bound(o => o.SightName).Width(100).Title("签到景点名").ReadOnly();
        columns.Bound(o => o.SightId).Width(200).Title("签到景点Id").Hidden();

        columns.Bound(o => o.Contents).Width(200).Title("签到内容")
            .HtmlAttributes(new { style = "overflow:hidden;" }).ReadOnly();

        columns.Bound(o => o.ClientId).Width(200).Title("客户端类型Id").Hidden();
        columns.Bound(o => o.IpAddress).Width(100).Title("添加IP").ReadOnly().Hidden();
        columns.Bound(o => o.AddTime).Width(200).Title("签到时间").ReadOnly();
        columns.Bound(o => o.SortNum).Width(100).Title("排序号").Hidden();
        columns.Bound(o => o.State).Width(100).Title("状态").Hidden();
    })
    .ClientEvents(clientEvents => clientEvents.OnDataBinding("dataBinding").OnComplete("bindComplete"))
    .DataKeys(key => key.Add("Id"))//添加主键
    .DataBinding(dataBinding => dataBinding.Ajax().Select("ajaxsightsiginindex", "sight"))
    .Pageable(page => page.PageSize(15))
    .Groupable()
    .Render();
}
<script type="text/javascript">
    function searchChange() {
        $("#SightSiginGrid").data("tGrid").rebind();
    }

    function dataBinding(args) {
        var searchKeyStr = $("#searchSightSigin").val();
        var targetId = $('#targetId').val();
        if (searchKeyStr == '用户名') {
            searchKeyStr = '';
        }
        args.data = $.extend(args.data, { targetId: targetId, searchKey: searchKeyStr });
    }

    function bindComplete(e) {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        var success = e.response.success;
        if (success != null && success != undefined) {
            alert(e.response.message);
            window.location.reload();
        }
    }

    $(function () {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        $('#checkAllRecords').click(function checkAll() { $("#SightSiginGrid tbody input:checkbox[name='selectRow']").attr("checked", this.checked); });

        $(":input[data-autocomplete]").each(function () {
            $(this).autocomplete({
                source: function (request, response) {
                    var url = '/sight/searchsightsigin/';
                    $.getJSON(url, {
                        term: $.trim(request.term),
                        targetId: $('#targetId').val()
                    }, response);
                }
            });
        });

        $("#searchSightSigin").focus(function () {
            if (this.value == "用户名") {
                $("#searchSightSigin").val("");
            }
        }).blur(function () {
            if (this.value == "") {
                $("#searchSightSigin").val("用户名");
            }
        });
    });
</script>
